<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>注册</title>
    <style>
        #btn{
            background: #fff;
            height: 1.88rem;
            line-height: 1.88rem;
            width: 30%;
            border: 1px solid #DBBB85;
            margin-left: 2%;
            text-align: center;
        }
    </style>
</head>
<script src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/jquerysession.js"></script>
<script src="js/common.js"></script>
<script src="css/layer/layer.js"></script>
<script src="js/mobiscroll.custom-3.0.0-beta4.min.js"></script>
<script>
    document.getElementsByTagName("html")[0].style.fontSize=document.documentElement.clientWidth/16+"px";
</script>
<body style="visibility:hidden;">
<script type="text/javascript">
    $.ajax({
        type:"get",
        url:"js/version.js?v="+new Date(),
        async:false
    });
    createLink('css/publicClear.css?v='+tj_ersion);
    createLink('css/publich5.css?v='+tj_ersion);
    createLink('css/sign.css?v='+tj_ersion,function(){
        $("body").css("visibility","visible");
    });
    //加载版本控制 js
    createJs("js/common.js");
    createJs("js/public.js");
</script>
<header class="header clear">
<!--    <span class="back"></span>-->
<!--    <a href="javascript:void(0)" class="mainLogo"></a>-->
    <h3 class="pageTitle">
        <script>writeI18nPageByKey("userReg")</script><!-- 注册 -->
    </h3>

</header>
<div class="scroll">
    <ul class="signList">
        <li>
            <input  class="signInput" type="text" name="" value="" id="phone" placeholder="请输入您的手机号">
        </li>
        <li>
            <input  class="signInput" style="width:66.4%;" type="text" name="" maxlength="6" value="" id="phoneCode" placeholder="请输入手机接收的验证码">
            <input type="button" id="btn" onclick="sendMobileCode(this,2,$('#phone').val())" value="发送验证码" />
        </li>
        <li>
            <input  class="signInput" type="password" name="" value="" id="pw" placeholder="密码由6-20位字母、数字或特殊符号组成">
        </li>
        <li id="referralCodeLi">
            <input class="signInput" type="text" name=""  id="referralCode" value="" placeholder="请输入推荐码">
        </li>
    </ul>
    <label class="userComment">
        <input type="checkbox" class="admission" checked/>
        <i></i>
        <span>
            <script>writeI18nPageByKey("agreeTip")</script><!-- 我已阅读并接受了 -->
        </span>
        <a href="javascript:void(0)" id="thePolicy">
            <script>writeI18nPageByKey("userAgreement")</script><!-- 《用户协议》 -->
        </a>
    </label>
    <div class="registerBox" onclick="SubmitCode()">
        <a href="javascript:void(0)">
            <script>writeI18nPageByKey("userReg")</script><!-- 注册 -->
        </a>
    </div>
</div>
<script>
    //回显推荐关系
    //let referralCode = getLocalStorageValue("referralCode");


    //微信头部隐藏========开始======
    // if(!isInApp()){
    //     $("header").hide();
    //     $(".scroll").css("padding-top","0.512rem");
    //     $(".scroll").css("margin-top","0rem");
    // }
    //微信头部隐藏=======结束===========

    if(is_weixn()){
        $("header").hide();
        $(".scroll").css("padding-top","0.512rem");
        //$("#referralCodeLi").hide();
    }

    var params=getParam(),referralCode = params.referralCode;

    if(isDefine(referralCode)){
        $("#referralCode").val(referralCode);
    }

    $(".back").click(function(){
        if (login) {
            window.location.href="Appsia_login.html?login="+login;
        }else if(loginBack==2){
            window.location.href="Appsia_login.html?loginBack="+loginBack;
        }else if(loginBack==3){
            window.location.href="Appsia_login.html?loginBack="+loginBack+"&goods_store="+goods_store+"&goods_id="+goods_id;
        }else if(loginBack==4){
            window.location.href="Appsia_login.html?loginBack="+loginBack+"&goods_store="+goods_store+"&goods_id="+goods_id;
        }else{
            window.location.href="Appsia_login.html";
        }
    })

    var instance=mobiscroll.select('#demo', {
        theme: 'mobiscroll',
        lang: 'zh',
        display: 'bottom',
        minWidth: 200  ,
    });
    $("#demo_dummy").css({"width":"10%"});
    var regEmail =/^[0-9A-Za-z]{4,20}$/;

    var numReg=/^1\d{10}$/;

    var regPs= /^(?![0-9]$)(?![a-zA-Z]$)[0-9A-Za-z]{6,20}$/;

    var codeReg=/^\d{6}$/;

    function SubmitCode(){
        if($("#phone").val()==""){
            layer.msg("手机号码不能为空");
            return;
        }
        else if(!numReg.test($("#phone").val())){
            layer.msg(getI18nPageByKey("phoneFormatError"));/*'手机号码格式错误'*/
            return;
        }
        else if($("#pw").val()==""){
            layer.msg(getI18nPageByKey("pwnotEmpty"));/*'密码不能为空'*/
            return;
        }else if(!regPs.test($("#pw").val())){
            layer.msg(getI18nPageByKey("PWformatError"));/*'密码格式不对'*/
            return;
        }
        else if($("#phoneCode").val()==''){
            layer.msg("验证码不能为空");/*'验证码不能为空'*/
            return;
        }else if(!codeReg.test($("#phoneCode").val())) {
            layer.msg("验证码不正确");
            return;
        }
        else if($("#phoneCode").val()=='' && $("#phoneCode")){
            layer.msg("点击发送验证码,验证手机");/*'两次输入密码不一致'*/
            return;
        } else if(!$(".admission").prop("checked")){
            layer.msg(getI18nPageByKey("pleaseAcceptAgreement"));/*"请同意用户协议！"*/
            return;
        }
        var reUrl = $.session.get("reUrl");

        if(is_weixn()){
            reUrl = "newInviteFriends.html";
        }
        Datas({
            url:"api/authService/register",
            datas:{
                "account":$('#phone').val(),
                "password":$("#pw").val(),
                // "regType":2,
                "msgCode":$('#phoneCode').val(),
                "referralCode":$('#referralCode').val()
            },
            success:function(data){
                if (data.code == 200) {
                    layer.msg("注册成功");
                    window.location.href= 'download.html';

                } else {
                    layer.msg(data.message);

                }
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                if(textStatus == 'error' && XMLHttpRequest.status == 0){
                    layer.msg(getI18nPageByKey("failToRequest"))
                }else if(textStatus == 'timeout'){
                    layer.msg("网络不给力，请点击屏幕重试");
                }
            }

        });
    }

    //当用户点击  用户协议时与存储  之前填写的内容
    $("#thePolicy").click(function(){
        $.session.set("theMobileNumber",$("#phone").val());
        $.session.set("PWord",$("#pw").val());
        window.location.href="agreement.html";
    })

    //所填内容 从用户协议页面 返回本页时 自动填写
    $(document).ready(function(){
        var theMobileNumber= $.session.get("theMobileNumber");
        var PWord= $.session.get("PWord");
        if(theMobileNumber==null){
            $("#phone").val("");
        }else{
            $("#phone").val(theMobileNumber);
        }
        if(PWord==null){
            $("#pw").val("");
        }else {
            $("#pw").val(PWord);
        }

    })
</script>
</body>
</html>